export function printByName(name){
  let LODOP = getCLodop();
   //初始化
   LODOP.PRINT_INITA(0, 0, '100%', '100%', '打印任务');

   // var count = LODOP.GET_PRINTER_COUNT();
   // var index=0;
   // for (var i = 0; i < count; i++) {
   //   //根据设备序号获取设备名
   //   var name = LODOP.GET_PRINTER_NAME(i);
   //   //找到设置的设备
   //   if(name===name){
   //     index=i;
   //     break;
   //   }
   // }
   //使用哪个打印机
   LODOP.SET_PRINTER_INDEXA(name);
   //字体大小
   //LODOP.SET_PRINT_STYLE("FontSize",11);
   LODOP.SET_PRINT_PAGESIZE(3, "58mm", "58mm", '')// 3代表纵向打印，宽度固定，高度按打印内容的高度自适应,纸张10*15
   for (var i = 0; i < 1; i++) {
    LODOP.NewPage()
    LODOP.ADD_PRINT_HTM("0mm","0mm","100%","100%","<a>www.baidu.com</a>")
    //LODOP.SET_PRINT_STYLEA(0, 'Stretch', 0)
   }

   //LODOP.SET_PREVIEW_WINDOW(0, 0, 0, 0, 0, '')

   //LODOP.Create_Printer_List(document.getElementById('printList'));
   // 这里实现的是选择打印机，数字代表打印机的型号，如果不需要预览，将LODOP.PREVIEW()改为LODOP.PRINT()
  //LODOP.PREVIEW();
   LODOP.PRINT()
}

export function printOneByName(name,content){
  let LODOP = getCLodop();
  //初始化
  LODOP.PRINT_INITA(0, 0, '100%', '100%', '打印任务');
  //使用哪个打印机
  LODOP.SET_PRINTER_INDEXA(name);
  //字体大小
  //LODOP.SET_PRINT_STYLE("FontSize",11);
  //LODOP.SET_PRINT_PAGESIZE(3, "58mm", "10mm", '')// 3代表纵向打印，宽度固定，高度按打印内容的高度自适应,纸张10*15
  LODOP.ADD_PRINT_HTM("0mm","0mm","100%","100%",content)
  LODOP.PRINT()
}
export function printListByName(name,list){
  let LODOP = getCLodop();
  //初始化
  LODOP.PRINT_INITA(0, 0, '100%', '100%', '打印任务');
  //使用哪个打印机
  LODOP.SET_PRINTER_INDEXA(name);
  //字体大小
  //LODOP.SET_PRINT_STYLE("FontSize",11);
  //LODOP.SET_PRINT_PAGESIZE(3, "58mm", "10mm", '')// 3代表纵向打印，宽度固定，高度按打印内容的高度自适应,纸张10*15
  list.forEach(function (item,index) {
    LODOP.NewPage()
    LODOP.ADD_PRINT_HTM("0mm","0mm","100%","100%",item)
  })
  LODOP.PRINT()
}

export function getPrinterList(){
  let LODOP = getCLodop();
  var count = LODOP.GET_PRINTER_COUNT();
  var list=[];
  for (var i = 0; i < count; i++) {
    //根据设备序号获取设备名
    var name = LODOP.GET_PRINTER_NAME(i);
    list.push({index:i,name:name})
  }
  return list;
}
